In [10]:
import pandas as pd
from datetime import date
import os
import time
import numpy as np
import glob
import seaborn as sns
import altair as alt
import matplotlib.pyplot as plt
from plotly import graph_objs as go
import plotly.offline as pyo
import ipywidgets as w
from IPython.display import display
pyo.init_notebook_mode()
%matplotlib inline
In [2]:
path = os.getcwd()+"/clean/"+"inventory_all.csv"
inventory = pd.read_csv(path,infer_datetime_format=True,parse_dates=True,encoding='utf8',index_col='VIN: ')
In [3]:
inventory.head()
Out[3]:
Unnamed: 0 EPA-Est MPG6: Engine: Exterior Color: Interior Color: Location‡: Stock #: Transmission: Vehicle Status: abSub finalPrice internetPrice msrp name scrapeDate year brand model cut priceChanged
VIN:
1FA6P8CF0L5114050 30330 16/25, 5.0L V-8 cyl, Shadow Black, Ebony, Suburban Ford of Sterling Heights NaN 6 speed manual, Dealer Ordered, 1963.0 NaN 40417.0 42380.0 2020 Ford Mustang Coupe V-8 cyl 2019-09-29 2020 Ford Mustang Coupe V-8 cyl True
1FA6P8CF0L5114050 30318 16/25, 5.0L V-8 cyl, Shadow Black, Ebony, Suburban Ford of Sterling Heights FL0407, 6 speed manual, Available in extended inventory, 3556.0 NaN 38824.0 42380.0 2020 Ford Mustang Coupe V-8 cyl 2019-10-18 2020 Ford Mustang Coupe V-8 cyl True
1FA6P8CF0L5114050 30319 16/25, 5.0L V-8 cyl, Shadow Black, Ebony, Suburban Ford of Sterling Heights FL0407, 6 speed manual, Available in extended inventory, 3556.0 NaN 38824.0 42380.0 2020 Ford Mustang Coupe V-8 cyl 2019-10-19 2020 Ford Mustang Coupe V-8 cyl True
1FA6P8CF0L5114050 30328 16/25, 5.0L V-8 cyl, Shadow Black, Ebony, Suburban Ford of Sterling Heights FL0407, 6 speed manual, Available in extended inventory, 3556.0 NaN 38824.0 42380.0 2020 Ford Mustang Coupe V-8 cyl 2019-10-27 2020 Ford Mustang Coupe V-8 cyl True
1FA6P8CF0L5114050 30327 16/25, 5.0L V-8 cyl, Shadow Black, Ebony, Suburban Ford of Sterling Heights NaN 6 speed manual, Dealer Ordered, 1963.0 NaN 40417.0 42380.0 2020 Ford Mustang Coupe V-8 cyl 2019-09-27 2020 Ford Mustang Coupe V-8 cyl True
In [4]:
sortedInventory = inventory[inventory["priceChanged"]==True].sort_values(by=["scrapeDate"])
In [11]:
trace1 = {
    'x': sortedInventory['scrapeDate'],
    'y': sortedInventory['internetPrice'],
    'type': 'box',
    'name':'col 1',
    'marker': {'color': 'blue'}
}
data = [trace1]

layout=dict(
    title='Subarban Ford Price Changes',
    xaxis=dict(
        title='scrapeDate', 
        type='date', 
        tickformat='%Y-%m-%d', 
        ticklen=5, 
        titlefont=dict(
            family='Old Standard TT, serif',
            size=20,
            color='black'
        )
    ),
    yaxis=dict(
        title='internetPrice', 
        ticklen=5,
        titlefont=dict(
            family='Old Standard TT, serif',
            size=20,
            color='black'
            )
        )

    )


fig = go.FigureWidget(data=data, layout=layout)

def update_fig(change):
    aux_df = sortedInventory[sortedInventory['model'] == change['new']]
    with fig.batch_update():
        for trace, column in zip(fig.data, ['internetPrice']):
            trace.x = aux_df['scrapeDate']
            trace.y = aux_df[column]
            
def update_fig2(change):
    aux_df = sortedInventory[sortedInventory['model'] == drop.value]
    aux_df = aux_df[aux_df['name'] == change['new']]
    with fig.batch_update():
        for trace, column in zip(fig.data, ['internetPrice']):
            trace.x = aux_df['scrapeDate']
            trace.y = aux_df[column]
            
drop = w.Dropdown(options=sortedInventory['model'].unique().tolist())
drop2 = w.Dropdown(options=sortedInventory['name'].unique().tolist())

drop.observe(update_fig, names='value')
drop2.observe(update_fig2, names='value')

display(w.VBox([w.HBox([drop, drop2]), fig]))
pyo.iplot(data, filename = 'ford_boxplot')
In [14]:
inventorycounts= inventory.groupby(['scrapeDate','model']).count()['name'].reset_index()
trace = {
    'x': inventorycounts['scrapeDate'],
    'y': inventorycounts['name'],
    'type': 'bar',
    'name':'col 1',
    'marker': {'color': 'blue'}
}
data = [trace]

layout=dict(
    title='Subarban Ford Inventory Changes',
    xaxis=dict(
        title='scrapeDate', 
        type='date', 
        tickformat='%Y-%m-%d', 
        ticklen=5, 
        titlefont=dict(
            family='Old Standard TT, serif',
            size=20,
            color='black'
        )
    ),
    yaxis=dict(
        title='# Cars', 
        ticklen=5,
        titlefont=dict(
            family='Old Standard TT, serif',
            size=20,
            color='black'
            )
        )

    )


fig = go.FigureWidget(data=data, layout=layout)

def update_fig1(change):
    aux_df = inventorycounts[inventorycounts['model'] == change['new']]
    with fig.batch_update():
        for trace, column in zip(fig.data, ['name']):
            trace.x = aux_df['scrapeDate']
            trace.y = aux_df[column]
            
drop = w.Dropdown(options=inventorycounts['model'].unique().tolist())
drop.observe(update_fig1, names='value')

display(w.VBox([drop, fig]))
pyo.iplot(data, filename = 'ford_inventory')
In [15]:
trace1 = {
    'x': sortedInventory['scrapeDate'],
    'y': sortedInventory['internetPrice'],
    'type': 'histogram2d',
    'name':'col 1',
    'colorscale':'YlGnBu'
}
data = [trace1]

layout=dict(
    title='Subarban Ford Price Change Heatmap',
    xaxis=dict(
        title='scrapeDate', 
        type='date', 
        tickformat='%Y-%m-%d', 
        ticklen=5, 
        titlefont=dict(
            family='Old Standard TT, serif',
            size=20,
            color='black'
        )
    ),
    yaxis=dict(
        title='internetPrice', 
        ticklen=5,
        titlefont=dict(
            family='Old Standard TT, serif',
            size=20,
            color='black'
            )
        )

    )


fig = go.FigureWidget(data=data, layout=layout)

def update_fig1(change):
    aux_df = sortedInventory[sortedInventory['model'] == change['new']]
    with fig.batch_update():
        for trace, column in zip(fig.data, ['name']):
            trace.x = aux_df['scrapeDate']
            trace.y = aux_df[column]
            
drop = w.Dropdown(options=sortedInventory['model'].unique().tolist())
drop.observe(update_fig1, names='value')

display(w.VBox([drop, fig]))
pyo.iplot(data, filename = 'ford_heatmap')